<template>
	<n-card :title="expName">
		<!-- 学生模块 -->
		<el-table :data="tableData" style="width: 100%">
			<el-table-column
				prop="eid"
				width="270"
				label="实验"
			></el-table-column>

			<el-table-column
				prop="name"
				width="160"
				label="姓名"
			></el-table-column>
			<el-table-column
				prop="sid"
				label="学号"
				width="160"
			></el-table-column>
			<el-table-column
				prop="updateTime"
				label="提交时间"
			></el-table-column>

			<el-table-column label="操作" width="180">
				<template #default="scope">
					<el-button
						type="success"
						size="small"
						@click="goToCheckExp(scope.row)"
						>开始批阅</el-button
					>
					<!-- <el-button type="warning" size="small">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>
	</n-card>
</template>
<script setup lang="ts">
//@ts-nocheck
import { getStudent, getExList } from '@/api/request'
const route = useRoute()
const router = useRouter()
const result = ref([])
const sid = route.query.sid
const jwtToken = localStorage.getItem('jwtToken')
const ws = new WebSocket(`ws://210.44.37.172:8082/message?id=1000&role=teacher`)
ws.onopen = function (e) {
	console.log('连接成功')
	// ws.send(
	// 	// '{"rid":"2002","tid":"3000","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// )
	// ws.send(
	// 	'{"role":"student","sourceId":"sid","eid":"","rid":"2002","destId":"tid","kid":"3000","value":"3.33","timeStamp":"3.2.3"}'
	// )
}
ws.onmessage = function (e) {
	console.log(e.data, '接收返回的消息')
}
ws.onclose = function () {
	console.log('连接关闭')
}
ws.onerror = function () {
	console.log('连接出错')
}
onMounted(() => {
	// console.log('实验的代号', route.params.scope)
	const jwtToken = localStorage.getItem('jwtToken')
	const cid = route.query.cid
	console.log(route.query.cid)
	// console.log(router)
	getExList(jwtToken, cid).then((res) => {
		console.log(res.data.data, '实验列表')
		result.value = res.data.data
		result.value = result.value.map((item) => ({
			rid: item.rid,
			eid: item.eid,
			sid: item.sid,
			cid: item.cid,
			name: item.name,
			updateTime: item.createTime,
			state: 0,
		}))
		result.value.forEach((element) => {
			// 把下面的if else 结构一直写到20
			if (element.eid === '1') {
				element.eid = '刚体转动惯量的测定'
			} else if (element.eid === '2') {
				element.eid = '振动法测材料的杨氏模量'
			} else if (element.eid === '3') {
				element.eid = '液体黏滞系数的测定'
			} else if (element.eid === '4') {
				element.eid = '液体表面张力系数的测定'
			} else if (element.eid === '5') {
				element.eid = '用稳态法测定不良导体的导热系数'
			} else if (element.eid === '6') {
				element.eid = 'AD590 集成电路温度传感器的特性研究及应用'
			} else if (element.eid === '7') {
				element.eid = '用板式电势差计测电源电动势'
			} else if (element.eid === '8') {
				element.eid = '电子示波器的使用'
			} else if (element.eid === '9') {
				element.eid = '电表改装与校准'
			} else if (element.eid === '10') {
				element.eid = '密立根油滴实验'
			} else if (element.eid === '11') {
				element.eid = '霍尔效应的测量和应用'
			} else if (element.eid === '12') {
				element.eid = '铁磁材料的磁滞回线和磁化曲线的测量'
			} else if (element.eid === '13') {
				element.eid = '磁阻效应及磁阻传感器特性的研究'
			} else if (element.eid === '14') {
				element.eid = '声速的测定'
			} else if (element.eid === '15') {
				element.eid = '用牛顿环仪测量透镜的曲率半径'
			} else if (element.eid === '16') {
				element.eid = '迈克尔逊干涉仪的调节与使用'
			} else if (element.eid === '17') {
				element.eid = '单缝衍射光强分布的测量'
			} else if (element.eid === '18') {
				element.eid = '用分光计测光波波长'
			} else if (element.eid === '19') {
				element.eid = '偏振光的研究'
			} else if (element.eid === '20') {
				element.eid = '压电陶瓷特性研究'
			}
			// else if(element.name==='')
		})
		tableData.value = result.value
	})
})
var classId = ref(0)
// 定义计算属性名为Id，根据expId的值，返回对应的实验名称
const expName = computed(() => {
	// 根据expId的值，为1时返回实验一，2时返回实验二，3时返回实验三
	var name = ''
	if (classId.value == 0) {
		name = '计算机科学与技术一班'
	} else if (classId.value == 1) {
		name = '计算机科学与技术二班'
	} else if (classId.value == 2) {
		name = '计算机科学与技术三班'
	} else if (classId.value == 3) {
		name = '计算机科学与技术四班'
	}
	return name
	// return expLists.value.find((item) => item.id === route.params.scope).name
})

// 计算属性，定义title，当
const tableData = ref([
	{
		id: '0',
		name: '张三',
		subTime: '2023.9.5 22:30',
		sno: '2021213725',
	},
	{
		id: '1',
		name: '李四',
		subTime: '2023.9.5 22:30',
		sno: '2021213725',
	},
	{
		id: '2',
		name: '王五',
		subTime: '2023.9.5 22:30',
		sno: '2021213725',
	},
	{
		id: '3',
		name: '赵六',
		subTime: '2023.9.5 22:30',
		sno: '2021213725',
	},
	{
		id: '4',
		name: '孙七',
		subTime: '2023.9.5 22:30',
		sno: '2021213725',
	},
])
const goToCheckExp = (element) => {
	// console.log('学生的学号', res)

	// 把下面的if else 结构一直写到20
	if (element.eid === '刚体转动惯量的测定') {
		element.eid = '1'
	} else if (element.eid === '振动法测材料的杨氏模量') {
		element.eid = '2'
	} else if (element.eid === '液体黏滞系数的测定') {
		element.eid = '3'
	} else if (element.eid === '液体表面张力系数的测定') {
		element.eid = '4'
	} else if (element.eid === '用稳态法测定不良导体的导热系数') {
		element.eid = '5'
	} else if (element.eid === 'AD590 集成电路温度传感器的特性研究及应用') {
		element.eid = '6'
	} else if (element.eid === '用板式电势差计测电源电动势') {
		element.eid = '7'
	} else if (element.eid === '电子示波器的使用') {
		element.eid = '8'
	} else if (element.eid === '电表改装与校准') {
		element.eid = '9'
	} else if (element.eid === '密立根油滴实验') {
		element.eid = '10'
	} else if (element.eid === '霍尔效应的测量和应用') {
		element.eid = '11'
	} else if (element.eid === '铁磁材料的磁滞回线和磁化曲线的测量') {
		element.eid = '12'
	} else if (element.eid === '磁阻效应及磁阻传感器特性的研究') {
		element.eid = '13'
	} else if (element.eid === '声速的测定') {
		element.eid = '14'
	} else if (element.eid === '用牛顿环仪测量透镜的曲率半径') {
		element.eid = '15'
	} else if (element.eid === '迈克尔逊干涉仪的调节与使用') {
		element.eid = '16'
	} else if (element.eid === '单缝衍射光强分布的测量') {
		element.eid = '17'
	} else if (element.eid === '用分光计测光波波长') {
		element.eid = '18'
	} else if (element.eid === '偏振光的研究') {
		element.eid = '19'
	} else if (element.eid === '压电陶瓷特性研究') {
		element.eid = '20'
	}
	// else if(element.name==='')
	// console.log(element.eid, 'aaaaaaaaa')
	router.push({
		path: `/review-paper/${element.eid}`,
		query: {
			eid: element.eid,
			rid: element.rid,
			name: element.name,
			sid: element.sid,
			cid: element.cid,
		},
	})
}
</script>

<style lang="less" scoped>
.bottom-content {
	padding: 14px;
	text-align: center;
	.bottom {
		margin-top: 13px;
		line-height: 12px;
		display: flex;
		align-items: center;
		justify-content: center;
		.button {
			padding: 18px;
			min-height: auto;
		}
	}
}

.image {
	width: 100%;
	display: block;
}
</style>
